package com.kanjj.mywebrtc.network;

import org.webrtc.DataChannel;

import java.nio.ByteBuffer;

class SimpleChannelObserver implements DataChannel.Observer {


    public SimpleChannelObserver() {

    }

    @Override
    public void onBufferedAmountChange(long l) {
        System.out.println("onBufferedAmountChange...");
    }

    @Override
    public void onStateChange() {
        System.out.println("onStateChange...");
    }

    @Override
    public void onMessage(DataChannel.Buffer buffer) {
        ByteBuffer data = buffer.data;
        byte[] bytes = new byte[data.capacity()];
        data.get(bytes);
        String msg = new String(bytes);
        System.out.println("================================:" + msg);
        int i = msg.indexOf(":");
        if(SocketClient.getInstance().listener != null) {
            SocketClient.getInstance().listener.onMessage(msg.substring(0, i), msg.substring(i));
        }
    }
}
